//
//  OneViewController.m
//  翻转效果
//
//  Created by Lucifer on 15-5-18.
//  Copyright (c) 2015年 xuxzhou. All rights reserved.
//

#import "OneViewController.h"
#import "AppDelegate.h"

#import "TwoViewController.h"
#import "loginPageViewController.h"
#import "shareViewController.h"
#import "MapViewController.h"
#import "netPageViewController.h"

#import "DataSaveViewController.h"
#import "WebCashViewController.h"
#import "calendarViewController.h"

#import "MasonryUseViewController.h"

#import "KDCycleBannerView.h"
#import "FunctionButtons.h"
#import "UIColor+Helper.h"
@interface OneViewController ()<UITableViewDataSource,UITableViewDelegate,KDCycleBannerViewDataource,KDCycleBannerViewDelegate>


@property(nonatomic,strong)UITableView * tabView;
@property(nonatomic,strong)NSMutableArray * dataArray;
@property(nonatomic,strong)UIButton * leftbutton;
@property(nonatomic,strong)UIButton * rightButton;

@property(nonatomic,strong)UIView * tabViewHeaderView;
@property(nonatomic,strong)KDCycleBannerView * cycleBannerWeb;
@property(nonatomic,strong)FunctionButtons * functionButs;
@property(nonatomic,strong) TwoViewController * towPage;
@end

@implementation OneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    void(^printBlock)(int number)=^(int number){
        NSLog(@"%d",number);
    };
    
    printBlock(9);
    
    
    
    _dataArray=[NSMutableArray arrayWithObjects:@"地图",@"数据库",@"支付",@"瀑布流", @"分享登录",@"图片浏览",@"线程",@"pods",@"上线材料",@"图表折线图",@"图片缓存清理collectionView",@"即时聊天",@"二维码",@"约束画UI",nil];
    
    
    _tabViewHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetWidth(self.view.frame))];
    _cycleBannerWeb=[[KDCycleBannerView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_tabViewHeaderView.frame), CGRectGetHeight(_tabViewHeaderView.frame)*0.5)];
//    _cycleBannerWeb.autoPlayTimeInterval=1;

    _cycleBannerWeb.datasource=self;
    _cycleBannerWeb.delegate=self;
    
    
    
    _functionButs=[[FunctionButtons alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_cycleBannerWeb.frame), CGRectGetWidth(_cycleBannerWeb.frame), CGRectGetHeight(_cycleBannerWeb.frame)) RowNum:4];
    
    _functionButs.itemsArray=@[@"地图",@"数据库",@"支付",@"瀑布流", @"分享",@"视频",@"语音",@"图片处理"];
    [_tabViewHeaderView addSubview:_functionButs];
    [_tabViewHeaderView addSubview:_cycleBannerWeb];
    [self buildTabView];
    [self buildButtonsOfNavBar];
    
    
    
    WS(weakSelf)
    _functionButs.FunctionButtonClickedBlock=^(NSInteger clikedIndex){
        NSLog(@"%ld",clikedIndex);
        switch (clikedIndex) {
            case 0://地图
            {
                MapViewController * mapView =[[MapViewController alloc]init];
                mapView.hidesBottomBarWhenPushed=YES;
                [weakSelf.navigationController pushViewController:mapView animated:YES];
            }
                break;
            case 1://数据库
            {
               
            }
                break;
                
            case 2://支付
            {
                
            }
                break;
            case 3://瀑布流
            {
                
            }
                break;
            case 4://分享
            {
                
            }
                break;
              case 5://视频
            {
                
            }
                break;
            case 6://语音
            {
                
            }
                break;
            case 7://图片处理
            {
                
            }
                break;
            default:
                break;
        }
    };
    
    
    
    
   
    
}
-(void)buildTabView{

    _tabView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-64-49)style:UITableViewStylePlain];
    
    _tabView.delegate=self;
    _tabView.dataSource=self;
    _tabView.tableHeaderView=_tabViewHeaderView;
    _tabView.tableFooterView=[[UIView alloc]init];
    [self.view addSubview:_tabView];


}
-(void)buildButtonsOfNavBar{
    self.navigationItem.title=@"iOS❤MySkill";
    
    _leftbutton=[UIButton buttonWithType:UIButtonTypeCustom];
    _leftbutton.frame=CGRectMake(0, 0, 44, 44);
    [_leftbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_leftbutton setTitle:@"翻转" forState:UIControlStateNormal];
    UIBarButtonItem * leftButton=[[UIBarButtonItem alloc]initWithCustomView:_leftbutton];
    [self.navigationItem setLeftBarButtonItem:leftButton];
    [_leftbutton addTarget:self action:@selector(buttonclicked) forControlEvents:UIControlEventTouchUpInside];
    _rightButton=[UIButton buttonWithType:UIButtonTypeCustom];
    _rightButton.frame=CGRectMake(0, 0, 44, 44);
    [_rightButton setTitle:@"个人" forState:UIControlStateNormal];
    [_rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIBarButtonItem * rightBar=[[UIBarButtonItem alloc]initWithCustomView:_rightButton];
    [self.navigationItem setRightBarButtonItem:rightBar];
    [_rightButton addTarget:self action:@selector(rightButtonCliked) forControlEvents:UIControlEventTouchUpInside];
    
    UISwipeGestureRecognizer * swipeGestureRe=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(loginPage:)];
    [self.view addGestureRecognizer:swipeGestureRe];


}
#pragma mark -KDCycleBannerViewDelegate

-(UIViewContentMode)contentModeForImageIndex:(NSUInteger)index{

    return UIViewContentModeScaleToFill;
}
-(NSArray *)numberOfKDCycleBannerView:(KDCycleBannerView *)bannerView{
    return @[[UIImage imageNamed:@"default.jpg"],[UIImage imageNamed:@"bottomlogo"]];
}

#pragma mark - tabViewDelegate

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UIView * sectionHeaderView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 40)];
    sectionHeaderView.backgroundColor=[UIColor colorE6E6E6];
    UILabel  * sectionHeaderLabel =[[UILabel alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(sectionHeaderView.frame)-20, CGRectGetHeight(sectionHeaderView.frame))];
    sectionHeaderLabel.text=@"What can I do for you";
    [sectionHeaderView addSubview:sectionHeaderLabel];
    return sectionHeaderView;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count ;
}
-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   static NSString * cellName =@"mySkillCell";
    UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:cellName];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellName];
    }
    cell.textLabel.text=_dataArray[indexPath.row];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    return cell;

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    switch (indexPath.row) {
        case 0:
        {
            
            [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
            
            MapViewController * mapView =[[MapViewController alloc]init];
            mapView.title=_dataArray[indexPath.row];
            mapView.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:mapView animated:YES];
            
        }
            break;
            
        case 1:
        {
            DataSaveViewController* dataSave =[[DataSaveViewController alloc]init];
            dataSave.title=_dataArray[indexPath.row];
            dataSave.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:dataSave animated:YES];
            
            
        }
            break;
      
        case 7:
        {
            netPageViewController * netPage =[[netPageViewController alloc]init];
            netPage.title=_dataArray[indexPath.row];
            netPage.hidesBottomBarWhenPushed=YES;
            netPage.webUrlStr=@"http://code4app.com/article/cocoapods-install-usage";
            [self.navigationController pushViewController:netPage animated:YES];
            
            
        }
            break;
            
        case 9:
        {
            calendarViewController* calendarPage =[[calendarViewController alloc]init];
            calendarPage.title=_dataArray[indexPath.row];
            calendarPage.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:calendarPage animated:YES];
            
            
        }
            break;
        case 10:
        {
            WebCashViewController * webCash =[[WebCashViewController alloc]init];
            webCash.title=_dataArray[indexPath.row];
            webCash.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:webCash animated:YES];
            
            
        }
            break;
        case 11:
        {
            MasonryUseViewController * webCash =[[MasonryUseViewController alloc]init];
            [self.navigationController pushViewController:webCash animated:YES];
            
            
        }
            break;
        default:
            break;
    }

}



#pragma mark - 各种点击
-(void)rightButtonCliked{
    [[[AppDelegate shareApplication] sideMenu]  presentRightMenuViewController];


}

-(void)buttonclicked{
    if (!_towPage) {
       _towPage = [[TwoViewController alloc] init];
       _towPage.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        _towPage.view.tag=100;
       [self.view addSubview:_towPage.view];
    }
    
    _leftbutton.selected=!_leftbutton.selected;
    if (_leftbutton.selected) {
        UIView * view =[self.view viewWithTag:100];
        
        view.hidden=NO;        
    }else{
         UIView * view =[self.view viewWithTag:100];
        view.hidden=YES;
    }


}
-(void)loginPage:(UISwipeGestureRecognizer *)swipeGesture{
    loginPageViewController * logInPage=[[loginPageViewController alloc]init];
    logInPage.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:logInPage animated:YES completion:^{
        
    }];

}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
